//
//  StaffInfoPartialView.m
//  ios-supplier
//
//  Created by feynmanyuan on 15/4/20.
//  Copyright (c) 2015年 feynmanyuan. All rights reserved.
//

#import "StaffInfoPartialView.h"
#import "JFBPhoneCallHelper.h"

@interface StaffInfoPartialView() {
    UIButton *_call;
    JFBPhoneCallHelper *_callHelper;
}
@property (weak, nonatomic) IBOutlet UILabel *staffInfoLabel;
@property (weak, nonatomic) IBOutlet UILabel *requireTimeLabel;


@end

@implementation StaffInfoPartialView

- (void)setOrder:(JFBOrderDS*)order{
    
    CGFloat fontSize = [order.orderType isEqualToString:@"complete"] ? TextFontSizeH3 : TextFontSizeH2;
    NSString *staff = [NSString stringWithFormat:@"配送员：%@(%@)", order.staff, order.staffMobile];
    CGSize staffSize = [staff sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:fontSize]}];
    
    CGFloat lineHeight = [order.orderType isEqualToString:@"complete"] ? staffSize.height + kOrderCellSpacing * 1.5 : kOrderCellHeaderHeight;
    
    
    CGFloat staffX = kOrderCellMargin, staffY = (lineHeight - staffSize.height) / 2;
    CGRect staffRect = CGRectMake(staffX, staffY, staffSize.width > self.bounds.size.width * 0.65 ? self.bounds.size.width * 0.65 : staffSize.width, staffSize.height);
    self.staffInfoLabel.font = [UIFont systemFontOfSize:fontSize];
    self.staffInfoLabel.text = staff;
    self.staffInfoLabel.frame = staffRect;
    
    
    NSString * requireTime =  [order.orderType isEqualToString:@"complete"] ? [NSString stringWithFormat:@"完成时间：%@", order.updateAt] : [NSString stringWithFormat:@"%@", order.requireTime];
    
    requireTime = [NSString isNilOrEmptyOrWhitespace:requireTime] ? order.remark : requireTime;
    
    CGSize requireTimeSize = [requireTime sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:fontSize]}];
    CGFloat requireTimeY = lineHeight + (lineHeight - requireTimeSize.height) / 2;
    CGFloat requireTimeX = kOrderCellSpacing;
    CGRect requireTimeRect = CGRectMake(requireTimeX, requireTimeY, requireTimeSize.width, requireTimeSize.height);
    self.requireTimeLabel.font = [UIFont systemFontOfSize:fontSize];
    self.requireTimeLabel.frame = requireTimeRect;
    self.requireTimeLabel.text = requireTime;
    
    if( [order.orderType isEqualToString:@"complete"] ) {
        self.requireTimeLabel.textColor = TextColorDefault;
    } else {
        _callHelper = [[JFBPhoneCallHelper alloc] initWithMobile:order.userMobile color:TextColorSpecialButton];
        _call = [_callHelper getButton];
        [self addSubview:_call];
        CGRect callRect = CGRectMake(self.bounds.size.width - kOrderCellSpacing - 88, kOrderCellSpacing, 88, 36);
        _call.frame = callRect;
        
        [self.drawLineHelper addHorizontalLine:0 y:lineHeight color:LineColorImportant width:self.bounds.size.width * 0.65];
    }
    self.height = lineHeight * 2;
}

@end
